package tarena.netctoss.view;

import java.util.List;

import tarena.netctoss.dao.Pagination;
import tarena.netctoss.dao.PricingCondition;
import tarena.netctoss.po.Pricing;
import tarena.netctoss.service.PricingService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 资费模块控制
 * 
 * @author Wangpeihu
 * @team [Never give up]
 * @since JDK1.6(建议)
 * @date 2010-3-2
 */
public class PricingAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	

	/** 资费信息 */
	private Pricing pricing;

	/** 资费业务方法 */
	private PricingService pricingService;

	/** 显示页数的条件 */
	private Pagination page;

	/** 查询资费基本条件 */
	private PricingCondition pc;

	private List<Pricing> pricingList;

	/**
	 * 依赖注入
	 * 
	 * @param pricingService
	 */
	public void setPricingService(PricingService pricingService) {
		this.pricingService = pricingService;
	}

	/**
	 * 资费浏览
	 * 
	 * @return
	 */
	public String feeBrowse() {
		// 分页条件
		if (null == page) {
			page = new Pagination();
			page.setPage(1);
			page.setPageSize(10);
		}
		// 查询条件
		if (null == pc) {
			pc = new PricingCondition();
		}

		// 查询 - list
		pricingList = pricingService.findAll(page, pc);
		// 跳到 success
		return SUCCESS;
	}

	/**
	 * 显示资费管理模块界面
	 * 
	 * @return
	 */
	public String index() {
		return SUCCESS;
	}

	/**
	 * 增加资费表单请求
	 * 
	 * @return
	 */
	public String feeAddForm() {
		return SUCCESS;
	}

	/**
	 * 增加资费
	 * 
	 * @return
	 */
	public String feeAdd() {
		if (pricing != null) {
			pricingService.save(pricing);
		}
		return SUCCESS;
	}

	/**
	 * 资费修改列表请求
	 * 
	 * @return
	 */
	public String feePrepareUpdate() {
		if (null == page) {
			page = new Pagination();
			page.setPage(1);
			page.setPageSize(10);
		}
		if (null == pc) {
			pc = new PricingCondition();
		}
		pricingList = pricingService.findAll(page, pc);
		return SUCCESS;
	}

	/**
	 * 资费修改界面请求
	 * 
	 * @return
	 */
	public String feeUpdateForm() {
		if (null != pricing) {
			pricing = pricingService.findById(pricing.getId());
		}
		return SUCCESS;
	}

	/**
	 * 资费修改
	 * 
	 * @return
	 */
	public String feeUpdate() {
		if (null != pricing) {
			pricingService.update(pricing);
		}
		return SUCCESS;
	}

	/**
	 * 资费删除表单请求
	 * 
	 * @return
	 */
	public String feeDeleteForm() {
		if (null == page) {
			page = new Pagination();
			page.setPage(1);
			page.setPageSize(10);
		}
		if (null == pc) {
			pc = new PricingCondition();
		}
		pricingList = pricingService.findAll(page, pc);
		return SUCCESS;
	}

	/**
	 * 资费删除
	 * 
	 * @return
	 */
	public String feeDelete() {
		if (null != pricing) {
			pricingService.delete(pricing);
		}
		return SUCCESS;
	}

	public Pagination getPage() {
		return page;
	}

	public void setPage(Pagination page) {
		this.page = page;
	}

	public PricingCondition getPc() {
		return pc;
	}

	public void setPc(PricingCondition pc) {
		this.pc = pc;
	}

	public List<Pricing> getPricingList() {
		return pricingList;
	}

	public void setPricingList(List<Pricing> pricingList) {
		this.pricingList = pricingList;
	}

	public Pricing getPricing() {
		return pricing;
	}

	public void setPricing(Pricing pricing) {
		this.pricing = pricing;
	}

}
